import { observable, action} from 'mobx';
import { ListViewPage,Form } from 'weaver-mobile-page';
import { Tools,Toast} from 'weaver-mobile';
import * as  Apis from '../../apis/govern';
//import ActionSheetStore from '../agent/actionSheetStore.js';
const getLabel = Tools.getLabel;
/*
 * @info: InfoStore
 * @Author: lusx
 * @Date: 2019-12-01 11:13:16
 * @Last modified by:   lusx
 * @Last modified time: 26-03-2019 02:49:26
 */
export default class InfoStore {
  @observable navTitle = '';//顶部导航栏标签名称/任务名称
  gridData = ['blog-normal','task-list','editor','blog-complete','left-branch'];//传入的菜单数据
  renderDom = [
    {text:getLabel("389235","任务内容"),color:'#f3bf44',renderKey:'content'},
    {text:getLabel("383349,24902","任务阶段"),color:'#67b6f6',renderKey:'level'},
    {text:getLabel("1008","审批意见"),color:'#87d0c3',renderKey:'opinion'},
    {text:getLabel("111","成文"),color:'#F14A2D',renderKey:'document'},
    {text:getLabel("111","进度视图"),color:'#008df7',renderKey:'mind'},
  ];//传入的菜单数据
  @observable form = new Form.Store({ route: '/pro/info/details' });
  @observable refreshing = false;//是否显示刷新状态
  pathname = '';
  isRight = 1;//是否有权限查看此页面
  isCommentRight = 1;//是否有权限进入OpinionPage页面
  @observable subtasksListStore = new ListViewPage.Store({ route: '/pro/:mainTab/info/level',id:'info' });
  //@observable actionSheetStore = new ActionSheetStore(this); //19.10.28 lusx 详情页面可进行分解,这里若初始化,那么form没有initForm,导致分解form为空
  constructor(props) {
    //super(props)
    this.initDatas = this.initDatas.bind(this);
    this.getProInfo = this.getProInfo.bind(this);
    this.getPathname = this.getPathname.bind(this);
    this.initInfoPage = this.initInfoPage.bind(this);
    this.getNavTitle = this.getNavTitle.bind(this);
    this.clearState = this.clearState.bind(this)
  }
  /**
   * 初始化方法
   * @method initDatas
   * @for InfoStore
   * @param {参数类型} {"id":String} 参数说明  列表每行id;
   * @return {返回值类型}
   */
  @action
  initDatas(params){
  }
  /**
   * 获取上级页面传递的数据
   * @method getNavTitle
   * @for InfoStore
   * @param {参数类型} {"navTitle":'','id':''} 参数说明  列表每行id;
   * @return {返回值类型}
   */
  @action
  getNavTitle(navTitle){
      this.navTitle = navTitle;
  }
  /**
   * 获取location.pathname 决定form渲染如何渲染
   * @method getPathname
   * @for InfoStore
   * @param {参数类型} 'String' 参数说明  列表每行id;
   * @return {返回值类型} 'String'
   */
   @action
   getPathname(pathname){
     this.pathname = pathname;
   }
  /**
   * info页面初始化
   * @method initInfoPage
   * @for InfoStore
   * @param {参数类型} {"id":String} 参数说明  列表每行id;
   * @return {返回值类型} {infoDetails}
   */
   @action
   initInfoPage(params){
     this.pathname === 'content' || this.pathname === 'level' ? this.getProInfo(params):null;
   }
  /**
   * Form初始化 ;当子任务多于3，则渲染为listViewPage
   * @method getProInfo
   * @for InfoStore
   * @param {参数类型} {"id":String} 参数说明  列表每行id;
   * @return {返回值类型} subtasksNum  参数说明  子任务个数
   */
  @action
  getProInfo(params){
    this.subtasksListStore.clearData();
    this.refreshing = true;
    this.loadingToast(true);
    this.form =  new Form.Store({ route: '/pro/info/details' });
     Apis.getProInfo(params).then((data) => {
      this.loadingToast(false);
       if (data.status === '1') {
         if(data.shareLevel === 0){//无进入详情页面权限
           this.isRight = 0;
           this.isCommentRight = 0;
         }else if (data.shareLevel >= 1) {//有内容/阶段权限
          this.form.initForm(data.condition1,`/pro/info/${this.pathname}`);
             this.isCommentRight = 0;
             //阶段页面
             let dataKey = {
               'dataKey': data.sessionkey
             }
             this.subtasksListStore.getData(dataKey);
             //内容页面
             
             if (data.shareLevel >= 2) {//有内容/阶段/进入评论页面权限
               this.isCommentRight = 1;
             }
         }
       }
      this.refreshing = false;
    });
  }
  @action
  clearState(){
    this.isRight = 1;
    this.isCommentRight = 1;
    this.form.resetFields();
    this.subtasksListStore.clearData();
  }

   //加载中
   loadingToast(isloading){
    Toast.hide();
    isloading ? Toast.loading('Loading...',0): Toast.hide();
  }
}
